package dao.impl;

import dao.StudentDao;
import pojo.Student;

import java.util.List;

public class StudentDaoImpl extends BaseDao implements StudentDao {
    @Override
    public int addStudent(Student student) {
        String sql="insert into student (sno,sname,sex,grade) values(?,?,?,?)";
        return update(sql,student.getSno(),student.getSname(),student.getSex(),student.getGrade());
    }

    @Override
    public int deleteStudentbySno(String sno) {
        String sql="delete from student where sno=?";
        return update(sql,sno);
    }

    @Override
    public int upDateStudent(Student student) {
        String sql="update student set sname=?, sex=?, grade=? where sno=?";
        return update(sql,student.getSname(),student.getSex(),student.getGrade(),student.getSno());
    }

    @Override
    public Student queryBookBySno(String sno) {
        String sql="select sno,sname,sex,grade from student where sno=?";
        return queryForOne(Student.class,sql,sno);
    }

    @Override
    public List<Student> queryStudent() {
        String sql = "select sno,sname,sex,grade from student";
        return queryForList(Student.class,sql);
    }
}
